<template>
  <van-dialog
      :value="value" 
      :show-confirm-button="showConfirmButton"
      :show-cancel-button="showCancelButton"
      :closeOnClickOverlay="closeOnClickOverlay"
      @open="onOpen"
      @input="val=>this.$emit('input',val)"
      @confirm="confirm"
    >
      <div class="dialog-content" :style="{'padding':showButtons?'40px 0;':'40px 0 0 0'}">
        <div class="dialog-title" :style="{'text-align':titlePosition=='left'?'left':(titlePosition=='center'?'center':'right')}">{{ title }}</div>
        <slot></slot>
        <div class="dialog-bottom" v-if="showButtons">
          <div></div>
          <div>
            <template v-if="isCustomButton">
              <slot name="buttons"></slot>
            </template>
            <template v-else>
              <span @click="close">取消</span>
              <span class="complete-btn" @click="confirm">{{confirmText}}</span>
            </template>
          </div>
        </div>
      </div>
    </van-dialog>
</template>
<script>
export default {
  name: "eagle-dialog",
  props: {
    value:{
      type:Boolean,
      default:false,
    },
    showConfirmButton: {
      type: Boolean,
      default: () => false,
    },
    closeOnClickOverlay: {
      type: Boolean,
      default: () => true,
    },
    title:{
        type:String,
        default:"询问"
    },
    confirmText:{
      type:String,
      default:"确定"
    },
    showCancelButton:{
      type:Boolean,
      default:()=>false
    },
    showButtons:{
      type:Boolean,
      default:()=>true
    },
    titlePosition:{
      type:String,
      default:()=>'left'
    },
    isCustomButton:{
      type:Boolean,
      default:()=>false
    }
  },
  data() {
    return {
    };
  },
  computed: {
  },
  methods:{
      onOpen(){
          this.$emit("open")
      },
      confirm(){
          this.$emit("confirm")
      },
      close(){
          this.$emit("close")
      }
  }
};
</script>
<style lang="less" scoped>
// 弹框
.dialog-content {
  position: relative;
  padding-top: 40px;

  .dialog-title,
  .dialog-bottom {
    width: 100%;
    position: fixed;
    left: 0;
    height: 40px;
    line-height: 40px;
    padding-left: 15px;
    font-size: 16px;
    background-color: #fff;
  }
  .dialog-title {
    top: 0;
  }
  .dialog-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    bottom: 0;
    padding: 0 15px;
    span {
      font-size: 14px;
      color: #666;
    }
    .complete-btn {
      color: rgb(0, 141, 101);
      margin-left: 20px;
    }
  }
}
</style>